﻿<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Default" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="bin\Debug\CustomTasks.tasks"/>
  <PropertyGroup >
    <VisualStudioDir>C:\Program Files (x86)\Microsoft Visual Studio 10.0\</VisualStudioDir>
    <MSTest>$(VisualStudioDir)Common7\IDE\mstest.exe</MSTest>
    <CodeMetrics>$(VisualStudioDir)Team Tools\Static Analysis Tools\FxCop\Metrics.exe</CodeMetrics>
    <ReportDir>Report</ReportDir>
  </PropertyGroup>

  <Target Name ="Test">
    <Message Text="Executing Unit Tests" />
    <RunAllTestsInSolution
              MSTest ="$(MSTest)"
              SolutionFile="AcceptanceTesting\TestData\Crap4Net.sln"
              Parmaters ="/resultsfile:TestResults.trx"
              Configuration="Debug"
              />
  </Target>

  <UsingTask AssemblyFile="3rdParties\NBehave\v3.5\NBehave.MSBuild.dll" TaskName="NBehave.MSBuild.NBehaveTask" />

  <ItemGroup>
    <AcceptanceReportFile Include="$(ReportDir)\*Acceptance*.*" />
    <MetricReportFiles Include="$(ReportDir)\Metrics*.*" />
  </ItemGroup>

  <Target Name="AcceptanceTests">
    <Delete Files="@(AcceptanceReportFile)"/>
    <NBehaveTask
     DryRun="false"
     FailBuild="false"
     XmlOutputFile="$(ReportDir)\tempAcceptanceResults.xml"
     TextOutputFile="$(ReportDir)\AcceptanceTests.txt"
     TestAssemblies="AcceptanceTesting\bin\Debug\AcceptanceTesting.dll"
     ScenarioFiles="AcceptanceTesting\Features\*.feature"/>

    <Copy SourceFiles="$(ReportDir)\tempAcceptanceResults.xml" DestinationFiles="$(ReportDir)\AcceptanceTests.xml" />
    <Exec Command="3rdParties\TransformXML\TransformXml.exe -i $(ReportDir)\AcceptanceTests.xml -o $(ReportDir)\AcceptanceResults.html -s 3rdParties\NBehave\v3.5\NBehaveResults.xsl" />

  </Target>
  
  <Target Name="CodeMetrics">
    <Message Text="Gathering Code Metrics" />
    <Delete Files="@(MetricReportFiles)"/>
    <ExportCodeMetrics
              CodeMetrics="$(CodeMetrics)"
              SolutionFile="CustomTasks.sln"
              OutputFile="$(ReportDir)\Metrics.xml"
              Parmaters =""
              Configuration="Debug"
              />
    <Exec Command="3rdParties\TransformXML\TransformXml.exe -i $(ReportDir)\Metrics.xml -o $(ReportDir)\Metrics.html -s RunAllTestsInSolution\xsl\MSCodeMetricsSummary.xsl" />
    <Exec Command="3rdParties\TransformXML\TransformXml.exe -i $(ReportDir)\Metrics.xml -o $(ReportDir)\MetricsDetails.html -s RunAllTestsInSolution\xsl\MSCodeMetricsDetails.xsl" />
  </Target>

</Project>
